﻿using System;
namespace Producers.Karis.Xtee.Riik.Ee.Producer.Karis {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="jisik_karistus", Namespace="http://producers.karis.xtee.riik.ee/producer/karis", Target=typeof(JisikKaristus))]
    public class JisikKaristusSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IJisikKaristus clazz;
        
        public JisikKaristusSerializer(IJisikKaristus clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("jisik");
            if (clazz.Jisik!=null) {
                global::Xtee.Core.SerializationMetadata metaJisik = this.GetMetaData(clazz.Jisik);
                Writer.WriteTypeAttribute(metaJisik.TypeQualifiedName.Namespace, metaJisik.TypeQualifiedName.Name);
                metaJisik.NewSerializer(clazz.Jisik).WriteXml(Writer);
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Jisik");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("karistus");
            if (clazz.Karistus!=null) {
                Writer.WriteTypeAttribute("http://schemas.xmlsoap.org/soap/encoding/", "Array");
                Writer.WriteArrayTypeAttribute("karistusandmed", "http://producers.karis.xtee.riik.ee/producer/karis", clazz.Karistus.Count);
                for (int x = 0; ((clazz.Karistus != null) 
                            && (x < clazz.Karistus.Count)); x = (x + 1)) {
                    if (clazz.Karistus[x]!=null) {
                        Writer.WriteStartElement("karistus");
                        global::Xtee.Core.SerializationMetadata metaKaristus = this.GetMetaData(clazz.Karistus[x]);
                        Writer.WriteTypeAttribute(metaKaristus.TypeQualifiedName.Namespace, metaKaristus.TypeQualifiedName.Name);
                        metaKaristus.NewSerializer(clazz.Karistus[x]).WriteXml(Writer);
                        Writer.WriteEndElement();
                    }
                }
            }
            else {
                Writer.WriteAttributeString("xsi", "nil", null, "1");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
        START:
            if ((Reader.LocalName == "jisik")) {
                goto jisik;
            }
            else {
                if ((Reader.LocalName == "karistus")) {
                    goto karistus;
                }
                else {
                    return;
                }
            }
        jisik:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>jisik_karistus>jisik");
            }
            global::Xtee.Core.SerializationMetadata metaJisik = this.GetMetaData<global::Producers.Karis.Xtee.Riik.Ee.Producer.Karis.IJIsik>(Reader, "JIsik", "http://producers.karis.xtee.riik.ee/producer/karis");
            clazz.Jisik = metaJisik.NewEntity<global::Producers.Karis.Xtee.Riik.Ee.Producer.Karis.IJIsik>();
            if ((Reader.IsEmptyElement == false)) {
                Reader.ReadStartElement("jisik");
                metaJisik.NewSerializer(clazz.Jisik).ReadXml(Reader);
                Reader.ReadEndElement();
            }
            else {
                Reader.Skip();
            }
            goto START;
        karistus:
            if ((Reader.IsElementNil() == false)) {
                clazz.Karistus = new System.Collections.Generic.List<global::Producers.Karis.Xtee.Riik.Ee.Producer.Karis.IKaristusandmed>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("karistus");
                    for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                && (Reader.LocalName == "karistus")); ) {
                        if (Reader.IsElementNil()) {
                            throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>jisik_karistus>karistus>karistus");
                        }
                        global::Xtee.Core.SerializationMetadata metaKaristus = this.GetMetaData<global::Producers.Karis.Xtee.Riik.Ee.Producer.Karis.IKaristusandmed>(Reader, "karistusandmed", "http://producers.karis.xtee.riik.ee/producer/karis");
                        global::Producers.Karis.Xtee.Riik.Ee.Producer.Karis.IKaristusandmed item = metaKaristus.NewEntity<global::Producers.Karis.Xtee.Riik.Ee.Producer.Karis.IKaristusandmed>();
                        clazz.Karistus.Add(item);
                        if ((Reader.IsEmptyElement == false)) {
                            Reader.ReadStartElement("karistus");
                            metaKaristus.NewSerializer(item).ReadXml(Reader);
                            Reader.ReadEndElement();
                        }
                        else {
                            Reader.Skip();
                        }
                    }
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                Reader.Skip();
            }
            goto START;
        }
    }
}
